<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../lib/html5shiv.js"></script>
    <script type="text/javascript" src="../lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <!--/meta 作为公共模版分离出去-->
    <title>查看用户列表</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="stylesheet" type="text/css" href="../myorder/myorder.css" />
</head>

<body>
    <article class="page-container">
        <div class="divsearch">
            <input type="text" placeholder="关键字搜索" maxlength="12" class="inputsearch">
            <input type="button" value="搜索" class="btnsearch" onclick="_funcreaduser(0);">
        </div>
        <div class="userview">
            <div class="uview">
                <div class="uleft">
                    <ul>
                        <li dataid="0" class="selected">所有用户</li>
                    </ul>
                </div>
                <div class="uright">
                    <ul>
                        <li></li>
                    </ul>
                </div>
            </div>
        </div>


    </article>

    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--/_footer /作为公共模版分离出去-->
    <script src="../lib/api.js"></script>


    <script type="text/javascript">

        //组别部门 包含哪些用户
        //部门Id 不为0的时候，表示给这个部门组 添加人员
        var _partid = 0;
        //选择用户模式
        var _isselect = false;

        $(function () {
            //获取参数中的ID

            var partstr = _apigetquery("partid");
            if (partstr != null) {
                _partid = parseInt(partstr);
            }

            var selectmodel = _apigetquery("model");
            if (selectmodel != null) {
                _isselect = true;
            }

            if (_partid == 0) {
                //部门Id为0 表示 项目参与者
                //读取部门列表
                //读取用户列表
                _apiget("/api/app/partInfo?page=1&size=200", true, function (code, obj) {
                    if (code == 200) {
                        var innerhtml = "";
                        for (var k = 0; k < obj.items.length; k++) {
                            var item = obj.items[k];
                            innerhtml += '<li dataid="' + item.id + '">' + item.name + '</li>';
                        }
                        $(".uleft").find("ul").append(innerhtml);
                    }
                });

            } else {
                $(".uleft").css('width', '0px');
                $(".uleft").hide();
            }

            _funcreaduser(0);

            $(".uleft").on('click', 'li', function () {
                $(this).siblings().removeClass("selected");
                var dataid = $(this).attr("dataid");
                $(this).addClass("selected");
                _funcreaduser(dataid);
            })

            if (!_isselect) {

                $(".uright").on("change", "input[type=checkbox]", function (e) {
                    var checkval = $(this).prop("checked");
                    var _that = $(this);
                    var dataid = $(this).parent().parent().attr("dataid");

                        _apipost("/api/app/User/UpdateUserPart?state=" + checkval + "&partid=" + _partid + "&userid=" + dataid, true, "", function (code, obj) {
                            if (code != 200) {
                                _that.prop("checked", !checkval);
                            }
                        });
                    
                })
            } else {
                $(".uright").on('click', 'li', function () {
                    _functionSelect(this);
                });
            }
        });

        function _functionSelect(elc) {
            var dataid = parseInt($(elc).attr("dataid"));
            var info = { id: dataid, name: $(elc).attr("datastr") };
            window.parent.postMessage({ type: 'userid', data: info });
            //关闭自己
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);  // 关闭layer
        }

        function _funcreaduser(partid) {

            $(".uright").find("ul").empty();
            if (_partid != 0) {
                partid = _partid;
            }
            var word =$(".inputsearch").val();

            _apiget("/api/app/User/ReadUserForBind?partid=" + partid+"&word="+word, true, function (code, obj) {
                if (code == 200) {
                    var strhtml = '';
                    for (var k = 0; k < obj.length; k++) {
                        var item = obj[k];
                        if (!_isselect) {
                            if (item.boolBind) {
                                strhtml += '<li dataid="' + item.id + '"><label><input type="checkbox" checked><img class="uhead" src="'+item.userHead+'">' + item.userName + '</label></li>';
                            } else {
                                strhtml += '<li dataid="' + item.id + '"><label><input type="checkbox"><img class="uhead" src="'+item.userHead+'">' + item.userName + '</label></li>';
                            }
                        } else {
                            strhtml += '<li dataid="' + item.id + '" datastr="' + item.userName + '"><label><img class="uhead" src="'+item.userHead+'">' + item.userName + '</label></li>';
                        }
                    }
                    $(".uright").find("ul").append(strhtml);
                }
            });
        }

    </script>
    <!--/请在上方写此页面业务相关的脚本-->
</body>

</html>